﻿using System.Collections.Generic;
using System.Data;
using POS.BusinessEntities;

namespace POS.DataObjects
{
    public class DOImpuesto: DOBase
    {
        #region Declarations

        private const string getListSP = "ImpuestoGetList";
        private const string saveSP = "ImpuestoSave";
        
        #endregion

        #region Methods: Public

        public virtual IList<BEImpuesto> GetList(int empresaId, string filter)
        {
            var result = new List<BEImpuesto>();

            var command = Db.GetStoredProcCommand(getListSP);
            Db.AddInParameter(command, "@empresaId", DbType.Int32, empresaId);
            Db.AddInParameter(command, "@filtro", DbType.String, filter);
            var data = Db.ExecuteDataSet(command);

            if (data.Tables.Count == 1)
            {
                foreach (DataRow row in data.Tables[0].Rows)
                    result.Add(CreateEntityFromDataRow<BEImpuesto>(row));
            }
            return result;
        }

        public virtual void Save(BEImpuesto entity, int empresaId, string user)
        {
            var command = Db.GetStoredProcCommand(saveSP);
            Db.AddInParameter(command, "@id", DbType.Int32, entity.Id);
            Db.AddInParameter(command, "@name", DbType.String, entity.Nombre);
            Db.AddInParameter(command, "@percentage", DbType.Decimal, entity.Porcentaje);
            Db.AddInParameter(command, "@companyId", DbType.Int32, empresaId);
            Db.AddInParameter(command, "@user", DbType.String, user);
            Db.ExecuteNonQuery(command);
        }

        #endregion
    }
}
